package per.lee.spingboothelper.db.converter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import per.lee.spingboothelper.db.model.Column;

public class DescConvertColumn {
	
	public static List<Column> convert(List<Map<String, Object>> queryForList) {
		if (queryForList == null) {
			return new ArrayList<Column>();
		}
		List<Column> columnModelList = new ArrayList<Column>();
		queryForList.forEach(x -> {
			columnModelList.add(new Column(x.get("Field").toString(),cleanType(x.get("Type"))));
		});
		return columnModelList;
	}
	private static String cleanType(Object type) {
		if(type == null) {
			return "";
		}
		String res = type.toString();
		if(res.indexOf("(") != -1) {
			return res.substring(0,res.indexOf("("));
		}
		return res;
		
	}
}
